package ads.pin.pinmon.business;

import java.sql.SQLException;
import java.util.List;

import ads.pin.pinmon.dal.SkillDAO;
import ads.pin.pinmon.entity.Skill;
import ads.pin.pinmon.exception.BusinessException;

public class SkillBO {

	/**
	 * 
	 * @param skill
	 * @throws BusinessException
	 */
	public void saveSkill(Skill skill) throws BusinessException {
		SkillDAO skillDAO = new SkillDAO();
		try {
			skillDAO.save(skill);
		} catch (SQLException e) {
			e.printStackTrace();
			// TODO add error msg -> failed to insert into database!
			throw new BusinessException(null);
		}

	}

	/**
	 * 
	 * @param skill
	 * @throws BusinessException
	 */
	public void updateSkill(Skill skill) throws BusinessException {
		SkillDAO skillDAO = new SkillDAO();
		try {
			skillDAO.update(skill);
		} catch (SQLException e) {
			e.printStackTrace();
			// TODO add error msg -> failed to insert into database!
			throw new BusinessException(null);
		}
	}

	/**
	 * 
	 * @param id
	 * @throws BusinessException
	 */
	public void deleteSkillById(int id) throws BusinessException {
		SkillDAO skillDAO = new SkillDAO();
		try {
			skillDAO.deleteById(id);
		} catch (SQLException e) {
			e.printStackTrace();
			// TODO add error msg -> failed to insert into database!
			throw new BusinessException(null);
		}
	}

	/**
	 * 
	 * @throws BusinessException
	 */
	public void deleteAllSkills() throws BusinessException {
		SkillDAO skillDAO = new SkillDAO();
		try {
			skillDAO.deleteAll();
		} catch (SQLException e) {
			e.printStackTrace();
			// TODO add error msg -> failed to insert into database!
			throw new BusinessException(null);
		}
	}

	/**
	 * 
	 * @param id
	 * @return
	 * @throws BusinessException
	 */
	public Skill searchSkillById(int id) throws BusinessException {
		SkillDAO skillDAO = new SkillDAO();
		try {
			return skillDAO.searchById(id);
		} catch (SQLException e) {
			e.printStackTrace();
			// TODO add error msg -> failed to insert into database!
			throw new BusinessException(null);
		}
	}

	/**
	 * 
	 * @param kind
	 * @return
	 * @throws BusinessException
	 */
	public List<Skill> searchSkillByKind(Object kind) throws BusinessException {
		SkillDAO skillDAO = new SkillDAO();
		try {
			return skillDAO.searchByKind(kind);
		} catch (SQLException e) {
			e.printStackTrace();
			// TODO add error msg -> failed to insert into database!
			throw new BusinessException(null);
		}
	}

	/**
	 * 
	 * @return
	 * @throws BusinessException
	 */
	public List<Skill> searchAllSkills() throws BusinessException {
		SkillDAO skillDAO = new SkillDAO();
		try {
			return skillDAO.searchAll();
		} catch (SQLException e) {
			e.printStackTrace();
			// TODO add error msg -> failed to insert into database!
			throw new BusinessException(null);
		}
	}
}
